package com.example.redisdemo.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * @author hexinglin
 * @created 2022-06-10 17:21
 **/

// ForkJoin代码演示
public class ForkJoinDemo01 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        // 创建ForkJoinTest对象
        ForkJoinTest task = new ForkJoinTest(1, 1000000);
        // 创建拆分合并池对象
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        // 提交任务
        ForkJoinTask<Integer> submit = forkJoinPool.submit(task);
        // 获取最终合并结果
        Integer result = submit.get();
        System.out.println(result);
        long endTime1 = System.currentTimeMillis();
        System.out.println("耗时1："+(endTime1-startTime));
        int re = 0;
        for (int i = 0; i <= 1000000; i++) {
            re+=i;
        }
        System.out.println(re);
        long endTime2 = System.currentTimeMillis();
        System.out.println("耗时2："+(endTime2-endTime1));

    }
}
